#include "../RepositoriesListPresenter.h"

#include <boost/bind.hpp>

#include <QDebug>

#include "views/IRepositoriesListView.h"
#include "../../common/services/ServiceLocator.h"
#include "../../common/services/IRepositoryService.h"
#include "../../common/models/dto/RepositoryDto.h"

// Constructor and destructor.

RepositoriesListPresenter::RepositoriesListPresenter(IRepositoriesListView *view)
	: AbstractPresenter<IRepositoriesListView>(view)
{
	//
}

RepositoriesListPresenter::~RepositoriesListPresenter()
{
	//
}

// Methods.

void RepositoriesListPresenter::setServiceLocator(ServiceLocator *serviceLocator)
{
	m_serviceLocator = serviceLocator;
}

void RepositoriesListPresenter::loadRepositoriesList()
{
	getRepositoryService()->beginGettingRepositoriesList(
		boost::bind(&RepositoriesListPresenter::RepositoriesListLoaded, this, _1),
		boost::bind(&RepositoriesListPresenter::RepositoriesListLoadError, this, _1));
}

// Helpers.

IRepositoryService *RepositoriesListPresenter::getRepositoryService() const
{
	return m_serviceLocator->getService<IRepositoryService>();
}

// Service callbacks.

void RepositoriesListPresenter::RepositoriesListLoaded(
	std::vector<RepositoryDto> *repositoriesList)
{
	delete repositoriesList;
}

void RepositoriesListPresenter::RepositoriesListLoadError(
	std::exception exception)
{
	//
}
